﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace Ankha.ContentPipeline
{
    public class FontIcon
    {
        public string FontName { get; set; }
        public SpriteFont Font { get; set; }

        public FontIcon(string fontName, SpriteFont font)
	    {
            FontName = fontName;
            Font = font;
	    }
    }

    public sealed class FontLibrary : IPipelineExtention
    {
        private static FontLibrary _Instance;
        public static FontLibrary Instance
        {
            get
            {
                if (_Instance == null)
                    _Instance = new FontLibrary();

                return _Instance;
            }
        }

        //Fields
        public string Name { get { return "FontLibrary"; } }
        private Dictionary<string, FontIcon> _FontBin;

        //ctor
        public FontLibrary()
        {
            _FontBin = new Dictionary<string, FontIcon>();
            AddFont("default");
        }

        //Methods
        public void AddFont(string name)
        {
            try
            {
                SpriteFont font = ScreenManager.GameBase.Content.Load<SpriteFont>("src/fonts/" + name);
                _FontBin.Add(name, new FontIcon(name, font));
                ScreenManager.DebugLogInstance.WriteString(string.Format("Loaded file 'src/fonts/{0}.spritefont' in {1}", name, this.GetType().Namespace));
            }
            catch (Exception)
            {
                ScreenManager.DebugLogInstance.WriteString(string.Format("Exception loading file 'src/fonts/{0}.spritefont' in {1}", name, this.GetType().Namespace));
            }
        }

        public SpriteFont GetFont(string name)
        {
            try
            {
                return _FontBin[name].Font;

            }
            catch (Exception)
            {
                ScreenManager.DebugLogInstance.WriteString(string.Format("Exception Getting Font '{0}' in {1}", name, this.GetType().Namespace));
                return _FontBin["default"].Font;
            }
        }
        public FontIcon GetFontIcon(string name)
        {
            try
            {
                return _FontBin[name];

            }
            catch (Exception)
            {
                ScreenManager.DebugLogInstance.WriteString(string.Format("Exception Getting Font '{0}' in {1}", name, this.GetType().Namespace));
                return _FontBin["default"];
            }
        }

        public void Load()
        {
            
        }

       
    }
}
